package com.cby.jetpack.sample.ext

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.widget.Toast

/**
 * @description: ActivityExt
 *
 * @author ChenBaoyang
 * @date 8/5/21 10:17
 */

/**
 * 打开一个无参数的Activity
 *
 * @receiver Activity
 * @param clazz Class<out Any>
 */
fun Activity.start(clazz: Class<out Any>) {
    startActivity(Intent(this, clazz))
}

/**
 * 打开一个带参数[data]的Activity
 *
 * @receiver Activity
 * @param clazz Class<out Any>
 * @param data Bundle
 */
fun Activity.start(clazz: Class<out Any>, data: Bundle) {
    val intent = Intent(this, clazz)
    intent.putExtras(data)
    startActivity(intent)
}

/**
 * Context的拓展函数，toast显示，
 *
 * @receiver Context
 * @param text String
 */
fun Context.showToast(text: String) {
    Toast.makeText(applicationContext, text, Toast.LENGTH_SHORT).show()
}